import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Test {
    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        testHeap.createHeap();

        testHeap.push(80);
        System.out.println(-1/2);

//        PriorityQueue

        int[] arr={3,12,6,9,10};
        int[] arr2=smallestK(arr, 3);
        for(int e:arr2){
            System.out.println(e);

            System.out.println("=======================");

            int[] arr3 = {12,3,7,1,19};
            PriorityQueue_Work priorityQueueWork = new PriorityQueue_Work();
            System.out.println("排前："+ Arrays.toString(priorityQueueWork.elem));
            priorityQueueWork.createHeap(arr3);
            System.out.println("排后："+ Arrays.toString(priorityQueueWork.elem));
            priorityQueueWork.push(8);
            System.out.println("排后："+ Arrays.toString(priorityQueueWork.elem));
            priorityQueueWork.pollHeap();
            System.out.println("排后："+ Arrays.toString(priorityQueueWork.elem));

        }
    }


    public static int[] smallestK(int[] arr, int k) {
        int[] arr2 = new int[k];
        if(arr==null||k==0) return arr2;
        PriorityQueue<Integer> prioriytQueue = new PriorityQueue<>();
        for(int i=0;i<arr.length;i++){
            prioriytQueue.offer(arr[i]);
        }
        for(int j=0;j<k;j++){
            arr2[j]=prioriytQueue.poll();
        }
        return arr2;
    }


    public int[] smallestK2(int[] arr, int k) {
        PriorityQueue<Integer> prioriytQueue = new PriorityQueue<>(new PComparator());
        int[] arr2 = new int[k];
        if(arr==null||k==0) return arr2;
        for (int i = 0; i < k; i++) {
            prioriytQueue.offer(arr[i]);
        }
        for (int i = k; i <arr.length ; i++) {
            if (arr[i]<prioriytQueue.peek()){
                prioriytQueue.poll();
                prioriytQueue.offer(arr[i]);
        }
    }
        for (int j=0;j<k;j++){
            arr2[j]=prioriytQueue.poll();
        }
        return arr2;

}
}
class PComparator implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
